﻿using System;
using System.Collections.Generic;
using System.Globalization;

namespace BoneSystem.Extensions
{
    public class Settings
    {
        private string _id;
        public string Name { get; set; }
        public string ParentFormName { get; set; }
        public string Class { get; set; }
        public string Style { get; set; }
        public int ColSpan { get; set; }
        public string Id
        {
            get
            {
                if (string.IsNullOrEmpty(_id))
                {
                    if (string.IsNullOrEmpty(Name))
                    {
                        throw new Exception("Propriedade Name não definida.");
                    }
                    else
                    {
                        _id = Name + "_I";
                    }
                }
                return _id;
            }
            set { _id = value; }
        }

        public int Width { get; set; }
        public bool Focused { get; set; }
        
        public Dictionary<string, string> GetAttributes()
        {
            var ret = new Dictionary<string, string>();
            
            ret["name"] = Name;
            ret["id"] = Id;
            ret["width"] = Width.ToString(CultureInfo.InvariantCulture);
            if (!string.IsNullOrEmpty(Class))
            {
                ret["class"] = Class;
            }
            
            if (!string.IsNullOrEmpty(Style))
            {
                ret["style"] = Style;
            }
            foreach (var attribute in Events.GetAttributes())
            {
                ret[attribute.Key] = attribute.Value;
            }
            return ret;
        }

        public Events Events { get; set; }
        public Settings()
        {
            Focused = true;
            Width = 100;
            Events = new Events();
            ColSpan = 1;

        }
    }
}